﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ExcelOperaiton
{
    public partial class MainForm : Form
    {

        List<SourceItem> sourceItems = new List<SourceItem>();

        /// <summary>
        /// 时间戳反转为时间，有很多中翻转方法，但是，请不要使用过字符串（string）进行操作，大家都知道字符串会很慢！
        /// </summary>
        /// <param name="TimeStamp">时间戳</param>
        /// <param name="AccurateToMilliseconds">是否精确到毫秒</param>
        /// <returns>返回一个日期时间</returns>
        public  DateTime GetTime(long TimeStamp, bool AccurateToMilliseconds = false)
        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
            if (AccurateToMilliseconds)
            {
                return startTime.AddTicks(TimeStamp * 10000);
            }
            else
            {
                return startTime.AddTicks(TimeStamp * 10000000);
            }
        }

        public MainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ExcelHelper excelHelper = new ExcelHelper(@"F:\2\source.xls");

            DataTable dt= excelHelper.ExcelToDataTable("sheet2", true);
           
            for(int i=0;i<dt.Rows.Count; i++)
            {
                sourceItems.Add(new SourceItem
                {
                    code = dt.Rows[i]["code"].ToString(),
                    vehicleno = dt.Rows[i]["vehicleno"].ToString(), 
                    materialname = dt.Rows[i]["materialname"].ToString(),
                    weighttime = GetTime(long.Parse(dt.Rows[i]["weighttime"].ToString()), true).ToString("yyyy-MM-dd HH:mm:ss")
                }); 
            }



        }
    }
}
